package com.yunji.web.base;

import com.yunji.aggregate.model.dto.base.MemberDTO;
import com.yunji.aggregate.service.BaseAggregateService;
import com.yunji.base.business.MemberBusiness;
import com.yunji.common.base.BaseController;
import com.yunji.common.base.response.Response;
import com.yunji.common.base.response.ResponseHelper;
import com.yunji.common.utils.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * @version 1.0
 * @Project: yunji-coffee
 * @Package com.yunji.web.user
 * @FileName MemberController.java
 * @Copyright Copyright © 2024 云集互联. All Rights Reserved
 * Company		com
 * @CreateTime 2024-04-08 13:50:12
 * @Description 用户管理交互
 * @Modification Author                    History Time			Version				Description
 * --------------------------------------------------------------------------------
 * HuaAo				2024-04-22 13:50:12		1.0					1.0 Version
 * @since JDK 1.8.0_202
 */
@Api(tags = "管理端-用户管理")
@RestController
@RequestMapping("/container/member")
public class MemberController extends BaseController {

    @Resource
    private MemberBusiness business;

    @Resource
    private BaseAggregateService aggregateService;

    @ApiOperation("查询用户列表")
    @GetMapping("/list")
    public Response<List<MemberDTO>> list(@Valid MemberDTO member) {
        List<MemberDTO> list = aggregateService.memberList(member);
        return ResponseHelper.successWithPage(list);
    }

    @ApiOperation("查询用户列表")
    @PreAuthorize("@ss.hasPermi('container:member:export')")
    @PostMapping("/export")
    public void export(MemberDTO member) {
        List<MemberDTO> list = aggregateService.memberList(member);
        ExcelUtil<MemberDTO> util = new ExcelUtil<>(MemberDTO.class);
        util.exportExcel(response, list, "用户数据");
    }

    /*-----------------------------------搜索-------------------------------*/
    @ApiOperation("用户昵称匹配搜索")
    @GetMapping("/searchName")
    public Response<List<String>> searchName(@RequestParam("name") String name) {
        return ResponseHelper.successWithPage(business.searchUserName(name));
    }

    @ApiOperation("手机号码匹配搜索")
    @GetMapping("/searchPhone")
    public Response<List<String>> searchPhone(@RequestParam("phone") String phone) {
        return ResponseHelper.successWithPage(business.searchPhone(phone));
    }
}